package reflect;

import reflect.annotations.AutoRunClass;
import reflect.annotations.AutoRunMethod;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, InvocationTargetException {
        Scanner scan =new Scanner(System.in);
        System.out.println("请输入一个类：");
        String line = scan.nextLine();
        Class c=Class.forName(line);

        if(c.isAnnotationPresent(AutoRunClass.class)) {
            Object o = c.newInstance();

            Method[] methods = c.getDeclaredMethods();
            for (Method method : methods) {
                if (method.isAnnotationPresent(AutoRunMethod.class)) {

                    System.out.println("调用方法：" + method.getName());
                    method.invoke(o);

                } else {
                    System.out.println("该类没有被AutoRunMethod标注");
                }


            }
        }}}
